<?php
include_once 'userConnector.php';
class DBBlog extends userConnector {

	protected  $con = null;

	function __construct(){
		//
	}

	public static function getBlogs($user_id){
		$con = self::StartUserConnector();
		
		$con->Select("Select * from blog where user_id = $user_id and release_date < NOW() ORDER BY release_date ASC");
		$Navis = $con->fetchobject();
		
		return $Navis;
	}	
	public static function getNavi($user_id,$select){
		$con = self::StartUserConnector();
		
		$con->Select('Select * from user_page_explorer where navi = 0 and user_id = '.$user_id.' ORDER BY navi_posi ASC');
		$Navis = $con->fetchobject();
		
		foreach ($Navis as $key => $navi){
		    if($navi->url == $select){
		       $Navis[$key]->NaviAktiv = 1;
		    } 
		}
		return $Navis;
	}
	public static function getCount($UserID){
		$con = self::StartUserConnector();
		$con->Select("Select count(*) as total from blog where user_id = $UserID and release_date < NOW()");
		$getTotal = $con->fetchobject();
		return $getTotal[0]->total;
	} 
    public static function getSetting($user_id){
		$con = self::StartUserConnector();
		$con->Select("SELECT * FROM blog_setting WHERE user_id ='$user_id'");
		$getTotal = $con->fetchobject();
		
		if(isset($getTotal[0])){
		    return $getTotal[0];
		}else{
		    return false;
		}
	}
    public static function updateDBSetting($user_id,$value){
        $con = self::StartUserConnector();

		$sql = "UPDATE blog_setting SET ";
		
		if(array_key_exists("overview_description",$value)){
		    $sql .= "overview_description = ".$value['overview_description'];
		}
        if(array_key_exists("limit",$value)){
		    $sql .= ", `limit` = ".$value['limit'];		    
		}
		
		$sql .= " WHERE user_id = ".$user_id;
		
		$con->Select($sql);
		
        if(!mysql_error()){
		    return true;
		}else{
		    return false;
		}
	}
    public static function setDbSetting($user_id,$overview_description = 0,$limit =5){
		$con = self::StartUserConnector();
		
		$sql = "INSERT INTO blog_setting (`ID`, `user_id`, `overview_description`, `limit`) VALUES (NULL, ".$user_id.", ".$overview_description.", ".$limit.")";
		$con->Select($sql);
		
		if(!mysql_error()){
		    return true;
		}else{
		    return false;
		}
	}
}

?>